<script setup="">
import {onMounted, ref, defineEmits} from "vue"
import {
  adminReplyFeedback,
} from "@/request/mid_interface.js";
import {ElMessage} from "element-plus";

const props = defineProps({
  param: {
    type: Object,
    required: false,
  }
})

const emit = defineEmits(["refresh", "close"]);

onMounted(() => {
  const {
    reply
  } = props.param
  feedbackReply.value = reply
})

async function confirmSend() {
  // 更新发布
  const postParam = {
    "feedback_id": props.param.feedback_id,
    "reply": feedbackReply.value,
  }
  const res = await adminReplyFeedback(postParam)
  if (res.code) {
    ElMessage.success("回复意见成功！")
    emit('refresh')
  } else {
    ElMessage.warning("请将信息填写完整")
  }
}

const feedbackReply = ref("")

</script>

<template>
  <div class=" px-24 py-8">

    <div class="flex items-center mt-6">
      <div class="w-24 pr-8 text-right">意见标题</div>
      <div class="flex-1 break-all">{{ param.title }}</div>
    </div>

    <div class="flex items-center mt-4">
      <div class="w-24 pr-8 text-right">意见内容</div>
      <div class="flex-1 break-all">{{ param.content }}</div>
    </div>

    <div class="flex items-center mt-4">
      <div class="w-24 pr-8 text-right"><span class="text-red-600">*</span> 姓名</div>
      <div class="flex-1 break-all">{{ param.name }}</div>
    </div>

    <div class="flex items-center mt-4">
      <div class="w-24 pr-8 text-right"><span class="text-red-600">*</span> 电话</div>
      <div class="flex-1 break-all">{{ param.phone }}</div>
    </div>

    <div class="flex items-center mt-4">
      <div class="w-24 pr-8 text-right">地址</div>
      <div class="flex-1 break-all">{{ param.address }}12345</div>
    </div>

    <!-- 我的回复 -->
    <div class="flex items-center mt-5">
      <div class="w-28 pr-8 text-right">我的回复</div>
      <el-input
          v-model="feedbackReply"
          placeholder="请输入回复内容"
          type="textarea"
          rows="6"
      >
      </el-input>
    </div>

    <div class="flex justify-center mt-16">
      <div @click="emit('close')"
           class="cursor-pointer select-none hover:opacity-70 px-5 py-2 border rounded font-bold">取消
      </div>
      <div @click="confirmSend"
           class="cursor-pointer select-none hover:opacity-70 px-5 py-2 border rounded font-bold ml-3 text-white"
           style="background: var(--themeColor); border: var(--themeColor);">确认
      </div>
    </div>

  </div>
</template>

<style scoped>
* {
  --el-pagination-hover-color: var(--themeColor);
  --el-input-focus-border-color: var(--themeColor);
}

/deep/ .el-dialog {
  border-radius: 20px !important;
}

/deep/ .m-2 {
  margin: 0;
}

/deep/ .el-input__wrapper {
  box-shadow: 0 0 0 1px #eee inset;
}

/deep/ .el-select__wrapper {
  box-shadow: 0 0 0 1px #eee inset;
}

/deep/ .el-input-group__append {
  transform: translateX(-1px);
  box-shadow: 0 0 0 1px #eee inset;
}
</style>
